<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增任务')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <h3>导入报表模板</h3>
        <form class="form-horizontal m" id="form-task-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">导入报表模板,下一秒自动识别</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file" multiple>
                </div>
            </div>
        </form>
        <div  class="col-lg-12 col-sm-12 col-md-12"><button type="button" class="btn btn-w-m btn-success" onclick="submitHandler()">下一步</button></div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var prefix = ctx + "gs/task"
        $("#form-task-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            var files=$('#filePath')[0].files
            for (var i=0;i<files.length;i++){
                var formData = new FormData();
                formData.append('file', $('#filePath')[0].files[i]);
                $.ajax({
                    url: ctx + "common/upload/",
                    type: 'post',
                    cache: false,
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: "json",
                    success: function(result) {
                        // console.info(enclosure)
                        // $.operate.successCallback(result);
                        $.ajax({
                            url: prefix + "/excelData",
                            type: 'post',
                            cache: false,
                            data: formData,
                            processData: false,
                            contentType: false,
                            dataType: "json",
                            success: function(result) {
                                console.info(result)
                                let url = prefix + "/customs";
                                $.modal.parentTab("自定义填写规范", url);
                                // $.operate.successCallback(result);
                            }
                        });
                    }
                });
            }


            // if ($.validate.form()) {
            //     $.operate.save(prefix + "/add", $('#form-task-add').serialize());
            // }
        }

        $("input[name='taskStartTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='taskEndTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>